<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>花礼网后台管理系统-分类管理</title>
    <base href="http://${pageContext.request.serverName }:${pageContext.request.serverPort }${pageContext.request.contextPath }/" />
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery-3.6.0.js"></script>
    <link rel="stylesheet" href="css/Top.css">
    <link rel="stylesheet" href="css/Left.css">
    <link rel="stylesheet" href="css/commodityList.css">
</head>
<body>
<div class="container-fluid">

    <div class="row">
        <div class="col-md-2 stick"><%@include file="Left.jsp"%></div>
        <div class="col-md-10 col-md-offset-2"><%@include file="Top.jsp"%></div>
        <div class="col-md-10 col-md-offset-2">

            <%--            模糊查询--%>
            <form class="form-inline" action="manager/commodityClassServlet?f=true" method="post">
                <div class="form-group">
                    <label>类别名称</label>
                    <input type="text" name="name" value="${sessionScope.className}" class="form-control" placeholder="支持模糊查询">
                </div>
                <div class="form-group">
                    <label>级别</label>
                    <select class="form-control" name="type">
                        <option value="">全部</option>
                        <c:forEach  begin="1" end="${requestScope.allType.size()}" var="t">
                            <option value="${t}">${t}级类别</option>
                        </c:forEach>
                    </select>
                </div>
                <button type="submit" class="btn btn-default">查询</button>
                <a href="manager/addCommodityClassServlet.shtml"><button type="button" class="btn btn-success">添加分类</button></a>
            </form>

            <%--查询的商品数据--%>
            <div class="box">
                <table class="table table-hover">
                    <th>编号</th>
                    <th>类别名称</th>
                    <th>所属分类</th>
                    <th>自身级别</th>
                    <th>查看</th>
                    <th>操作</th>
                    <c:forEach items="${requestScope.classPage.list}" var="c">
                        <tr class="datarow">
                            <td>${c.id}</td>
                            <td>${c.name}</td>
                            <td>${c.pName}</td>
                            <td>${c.type}级类别</td>
                            <td>
                                <c:if test="${c.type!=3}">
                                    <a href="manager/commodityClassServlet?id=${c.id}&f=0">子分类</a>
                                </c:if>
                            </td>
                            <td>
                                <a href="manager/updateCommodityClassServlet.shtml?id=${c.id}&pageNo=${requestScope.classPage.pageNum}"><button type="button" class="btn btn-info">修改</button></a>
                                <a href="manager/deleteCommodityClassServlet.shtml?id=${c.id}"><button type="button" class="btn btn-danger">删除</button></a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
            <%--分页数据--%>
            <div class="box">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <c:set var="p" value="${requestScope.classPage}"></c:set>
                            <a href="manager/commodityClassServlet?pageNo=${p.prePage<1?1:p.prePage}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li><a href="manager/commodityClassServlet?pageNo=1">首页</a></li>
                        <c:forEach items="${requestScope.classPage.navigatepageNums}" var="i">
                            <c:if test="${i==requestScope.classPage.pageNum}" var="f">
                                <li class="active"><a href="manager/commodityClassServlet?pageNo=${i}">${i}</a></li>
                            </c:if>
                            <c:if test="${!f}">
                                <li><a href="manager/commodityClassServlet?pageNo=${i}">${i}</a></li>
                            </c:if>
                        </c:forEach>
                        <li><a href="manager/commodityClassServlet?pageNo=${requestScope.classPage.pages}">末页</a></li>
                        <li>
                            <a href="manager/commodityClassServlet?pageNo=${p.nextPage==0?p.pages:p.nextPage}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        共${requestScope.classPage.total}条数据，共${requestScope.classPage.pages}页
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function (){
        //左侧‘分类管理’变红
        $("#ul li:nth-child(5) a").css("color","red");
        $("#let").html("分类管理");

        //获取保存在session里的模糊查询条件
        $("[name='type']").val(${sessionScope.classType})


    })
</script>

</html>
